package cn.changshengjue.dakong.command.sub;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

import cn.changshengjue.dakong.main;
import cn.changshengjue.dakong.command.SubCommand;
import cn.changshengjue.dakong.command.type.AdminCommand;
import cn.changshengjue.dakong.config.cfg;
import cn.changshengjue.dakong.utils.ItemSerialize;
import cn.changshengjue.dakong.utils.Utils;
import cn.changshengjue.dakong.utils.YmlUtil;

public class SetCommand extends SubCommand implements AdminCommand {
	public SetCommand() {
		super("set", "/dk set [id]", main.getInstance().getConfig().getString("commands.set"));
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		Player p = Bukkit.getPlayer(sender.getName());

		ItemStack itemInMainHand = p.getItemInHand();
		if (Utils.itemDisplayNameAndLoreIsNull(itemInMainHand) == false) {
			YmlUtil ymlUtil = new YmlUtil();
			File file = ymlUtil.getFile("item.yml");
			FileConfiguration fileMine = ymlUtil.getFileMine(file);
			fileMine.set(args[1], new ItemSerialize().getItemString(itemInMainHand));
			ymlUtil.saveFiles(file, fileMine);
			p.sendMessage(cfg.MSG_PLUGIN + cfg.MSG_SET);
		} else {
			p.sendMessage(cfg.MSG_PLUGIN + cfg.MSG_SET_1);
		}
		return false;
	}

	@Override
	public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
		return null;
	}

}
